package com.example.controller;

import com.alibaba.fastjson.JSON;
import com.example.domain.ExportTask;
import com.example.domain.Task;
import com.example.service.ExportTaskServiceImpl;
import com.example.service.ReqServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
//@Slf4j
public class ReqController {
    private static final Logger log = LoggerFactory.getLogger(ReqController.class);


    @Autowired
    private ReqServiceImpl reqService;

    @Autowired
    private ExportTaskServiceImpl exportTaskService;


    /***
     * 通过PlatformTransactionManager实现编程式事务（不推荐）
     */
    @RequestMapping(value = "/test/batch")
    public void batchInsert() {
        log.info("执行方法");
        ExportTask ter = new ExportTask();
        ter.setTaskName("333");
        Task task = new Task();
        task.setName("12121");
        ter.setTaskParams(task);
        ExportTask ter1 = new ExportTask();
//        ter1.setTaskName("333");
        Task task1 = new Task();
        task1.setName("12121");
        ter1.setTaskParams(task);
        List<ExportTask> list = new ArrayList<>();
        list.add(ter);
        list.add(ter1);
        reqService.save(list);


    }


    @RequestMapping(value = "/test/batch1")
    public void batchInsert1() {
        log.info("执行方法");
        ExportTask ter = new ExportTask();
        ter.setTaskName("333");
        Task task = new Task();
        task.setName("12121");
        ter.setTaskParams(task);
        ExportTask ter1 = new ExportTask();
//        ter1.setTaskName("333");
        Task task1 = new Task();
        task1.setName("12121");
        ter1.setTaskParams(task);
        List<ExportTask> list = new ArrayList<>();
        list.add(ter);
        list.add(ter1);
        exportTaskService.save1(list);


    }

}
